package com.hwadee.caixiang.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.hwadee.caixiang.entity.User;
import com.hwadee.caixiang.service.LoginService;

@Controller
public class LoginController {

	@Autowired
	private LoginService loginservice;

	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String get() {

		return "login";
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String post(String username, String password,HttpSession session) {
		// forward
		User user = loginservice.login(username, password);
		session.setAttribute("user", user);
		if (user != null)
			return "redirect:index.jsp";
		else
			return "redirect:/login.jsp";
	}
}
